import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn } from 'typeorm';
import { Course } from '../../course/entities/course.entity';
import { Teacher } from '../../teacher/entities/teacher.entity';
import { Semester } from '../../semester/entities/semester.entity';

@Entity('course_offering')
export class CourseOffering {
    @PrimaryGeneratedColumn()
    offering_id: number;

    @ManyToOne(() => Course)
    @JoinColumn({ name: 'cno' })
    course: Course;

    @ManyToOne(() => Semester)
    @JoinColumn({ name: 'semester_id' })
    semester: Semester;

    @ManyToOne(() => Teacher, { nullable: true })
    @JoinColumn({ name: 'tno', referencedColumnName: 'tno' })
    readonly teacher: Teacher;

    @Column({ name: 'capacity', type: 'int', default: 50 })
    capacity: number;

    @Column({ name: 'location', type: 'varchar', length: 100 })
    location: string;

    @Column({ name: 'enrolled_count', type: 'int', default: 0 })
    enrolled_count: number;  // 已选人数
    
    @Column({ name: 'status', type: 'enum', enum: ['open', 'closed', 'cancelled'], default: 'open' })
    status: string;  // 课程状态
}